using System;
using System.Collections.Generic;

namespace UserInterface.UserControls
{
    public partial class Messages : System.Web.UI.UserControl
    {
        private IList<string> criticalMessages;
        private IList<string> exclamationMessages;
        private IList<string> informationMessages;
        private IList<string> permissionMessages;
        private IList<string> successMessages;

        public void BindData()
        {
            if (criticalMessages == null && exclamationMessages == null && informationMessages == null && permissionMessages == null && successMessages == null)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = true;

                criticalRepeater.DataSource = criticalMessages;
                criticalRepeater.DataBind();

                exclamationRepeater.DataSource = exclamationMessages;
                exclamationRepeater.DataBind();

                informationRepeater.DataSource = informationMessages;
                informationRepeater.DataBind();

                permissionRepeater.DataSource = permissionMessages;
                permissionRepeater.DataBind();

                successRepeater.DataSource = successMessages;
                successRepeater.DataBind();
            }
        }

        public void AddCritical(string message)
        {
            if (criticalMessages == null)
            {
                criticalMessages = new List<string>();
            }
            criticalMessages.Add(message);
        }

        public void AddExclamation(string message)
        {
            if (exclamationMessages == null)
            {
                exclamationMessages = new List<string>();
            }
            exclamationMessages.Add(message);
        }

        public void AddInformation(string message)
        {
            if (informationMessages == null)
            {
                informationMessages = new List<string>();
            }
            informationMessages.Add(message);
        }

        public void AddPermission(string message)
        {
            if (permissionMessages == null)
            {
                permissionMessages = new List<string>();
            }
            permissionMessages.Add(message);
        }

        public void AddSuccess(string message)
        {
            if (successMessages == null)
            {
                successMessages = new List<string>();
            }
            successMessages.Add(message);
        }

        public int CriticalCount
        {
            get { return GetMessageCount(criticalMessages); }
        }

        public int ExclamationCount
        {
            get { return GetMessageCount(exclamationMessages); }
        }

        public int InformationCount
        {
            get { return GetMessageCount(informationMessages); }
        }

        public int PermissionCount
        {
            get { return GetMessageCount(permissionMessages); }
        }

        public int SuccessCount
        {
            get { return GetMessageCount(successMessages); }
        }

        private int GetMessageCount(IList<string> messages)
        {
            if (messages == null)
            {
                return 0;
            }
            else
            {
                return messages.Count;
            }
        }
    }
}